home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / Python1.4_Source / Objects / listobject.c < prev    next >
C/C++ Source or Header  |  1998-06-24  |  15KB  |  811 lines

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. /* List object implementation */
  33.  
  34. #include "allobjects.h"
  35. #include "modsupport.h"
  36. #include "ceval.h"
  37. #ifdef STDC_HEADERS
  38. #include <stddef.h>
  39. #else
  40. #include <sys/types.h>        /* For size_t */
  41. #endif
  42.  
  43. #include "protos/listobject_protos.h"
  44.  
  45. #define ROUNDUP(n, block) ((((n)+(block)-1)/(block))*(block))
  46.  
  47. static int
  48. roundup(n)
  49.     int n;
  50. {
  51.     if (n < 500)
  52.         return ROUNDUP(n, 10);
  53.     else
  54.         return ROUNDUP(n, 100);
  55. }
  56.  
  57. #define NRESIZE(var, type, nitems) RESIZE(var, type, roundup(nitems))
  58.  
  59. object *
  60. newlistobject(size)
  61.     int size;
  62. {
  63.     int i;
  64.     listobject *op;
  65.     size_t nbytes;
  66.     if (size < 0) {
  67.         err_badcall();
  68.         return NULL;
  69.     }
  70.     nbytes = size * sizeof(object *);
  71.     /* Check for overflow */
  72.     if (nbytes / sizeof(object *) != size) {
  73.         return err_nomem();
  74.     }
  75.     op = (listobject *) malloc(sizeof(listobject));
  76.     if (op == NULL) {
  77.         return err_nomem();
  78.     }
  79.     if (size <= 0) {
  80.         op->ob_item = NULL;
  81.     }
  82.     else {
  83.         op->ob_item = (object **) malloc(nbytes);
  84.         if (op->ob_item == NULL) {
  85.             free((ANY *)op);
  86.             return err_nomem();
  87.         }
  88.     }
  89.     op->ob_type = &Listtype;
  90.     op->ob_size = size;
  91.     for (i = 0; i < size; i++)
  92.         op->ob_item[i] = NULL;
  93.     NEWREF(op);
  94.     return (object *) op;
  95. }
  96.  
  97. int
  98. getlistsize(op)
  99.     object *op;
  100. {
  101.     if (!is_listobject(op)) {
  102.         err_badcall();
  103.         return -1;
  104.     }
  105.     else
  106.         return ((listobject *)op) -> ob_size;
  107. }
  108.  
  109. static object *indexerr;
  110.  
  111. object *
  112. getlistitem(op, i)
  113.     object *op;
  114.     int i;
  115. {
  116.     if (!is_listobject(op)) {
  117.         err_badcall();
  118.         return NULL;
  119.     }
  120.     if (i < 0 || i >= ((listobject *)op) -> ob_size) {
  121.         if (indexerr == NULL)
  122.             indexerr = newstringobject("list index out of range");
  123.         err_setval(IndexError, indexerr);
  124.         return NULL;
  125.     }
  126.     return ((listobject *)op) -> ob_item[i];
  127. }
  128.  
  129. int
  130. setlistitem(op, i, newitem)
  131.     register object *op;
  132.     register int i;
  133.     register object *newitem;
  134. {
  135.     register object *olditem;
  136.     register object **p;
  137.     if (!is_listobject(op)) {
  138.         XDECREF(newitem);
  139.         err_badcall();
  140.         return -1;
  141.     }
  142.     if (i < 0 || i >= ((listobject *)op) -> ob_size) {
  143.         XDECREF(newitem);
  144.         err_setstr(IndexError, "list assignment index out of range");
  145.         return -1;
  146.     }
  147.     p = ((listobject *)op) -> ob_item + i;
  148.     olditem = *p;
  149.     *p = newitem;
  150.     XDECREF(olditem);
  151.     return 0;
  152. }
  153.  
  154. static int
  155. ins1(self, where, v)
  156.     listobject *self;
  157.     int where;
  158.     object *v;
  159. {
  160.     int i;
  161.     object **items;
  162.     if (v == NULL) {
  163.         err_badcall();
  164.         return -1;
  165.     }
  166.     items = self->ob_item;
  167.     NRESIZE(items, object *, self->ob_size+1);
  168.     if (items == NULL) {
  169.         err_nomem();
  170.         return -1;
  171.     }
  172.     if (where < 0)
  173.         where = 0;
  174.     if (where > self->ob_size)
  175.         where = self->ob_size;
  176.     for (i = self->ob_size; --i >= where; )
  177.         items[i+1] = items[i];
  178.     INCREF(v);
  179.     items[where] = v;
  180.     self->ob_item = items;
  181.     self->ob_size++;
  182.     return 0;
  183. }
  184.  
  185. int
  186. inslistitem(op, where, newitem)
  187.     object *op;
  188.     int where;
  189.     object *newitem;
  190. {
  191.     if (!is_listobject(op)) {
  192.         err_badcall();
  193.         return -1;
  194.     }
  195.     return ins1((listobject *)op, where, newitem);
  196. }
  197.  
  198. int
  199. addlistitem(op, newitem)
  200.     object *op;
  201.     object *newitem;
  202. {
  203.     if (!is_listobject(op)) {
  204.         err_badcall();
  205.         return -1;
  206.     }
  207.     return ins1((listobject *)op,
  208.         (int) ((listobject *)op)->ob_size, newitem);
  209. }
  210.  
  211. /* Methods */
  212.  
  213. static void
  214. list_dealloc(op)
  215.     listobject *op;
  216. {
  217.     int i;
  218.     if (op->ob_item != NULL) {
  219.         for (i = 0; i < op->ob_size; i++) {
  220.             XDECREF(op->ob_item[i]);
  221.         }
  222.         free((ANY *)op->ob_item);
  223.     }
  224.     free((ANY *)op);
  225. }
  226.  
  227. static int
  228. list_print(op, fp, flags)
  229.     listobject *op;
  230.     FILE *fp;
  231.     int flags;
  232. {
  233.     int i;
  234.     fprintf(fp, "[");
  235.     for (i = 0; i < op->ob_size; i++) {
  236.         if (i > 0)
  237.             fprintf(fp, ", ");
  238.         if (printobject(op->ob_item[i], fp, 0) != 0)
  239.             return -1;
  240.     }
  241.     fprintf(fp, "]");
  242.     return 0;
  243. }
  244.  
  245. static object *
  246. list_repr(v)
  247.     listobject *v;
  248. {
  249.     object *s, *comma;
  250.     int i;
  251.     s = newstringobject("[");
  252.     comma = newstringobject(", ");
  253.     for (i = 0; i < v->ob_size && s != NULL; i++) {
  254.         if (i > 0)
  255.             joinstring(&s, comma);
  256.         joinstring_decref(&s, reprobject(v->ob_item[i]));
  257.     }
  258.     XDECREF(comma);
  259.     joinstring_decref(&s, newstringobject("]"));
  260.     return s;
  261. }
  262.  
  263. static int
  264. list_compare(v, w)
  265.     listobject *v, *w;
  266. {
  267.     int len = (v->ob_size < w->ob_size) ? v->ob_size : w->ob_size;
  268.     int i;
  269.     for (i = 0; i < len; i++) {
  270.         int cmp = cmpobject(v->ob_item[i], w->ob_item[i]);
  271.         if (cmp != 0)
  272.             return cmp;
  273.     }
  274.     return v->ob_size - w->ob_size;
  275. }
  276.  
  277. static int
  278. list_length(a)
  279.     listobject *a;
  280. {
  281.     return a->ob_size;
  282. }
  283.  
  284. static object *
  285. list_item(a, i)
  286.     listobject *a;
  287.     int i;
  288. {
  289.     if (i < 0 || i >= a->ob_size) {
  290.         if (indexerr == NULL)
  291.             indexerr = newstringobject("list index out of range");
  292.         err_setval(IndexError, indexerr);
  293.         return NULL;
  294.     }
  295.     INCREF(a->ob_item[i]);
  296.     return a->ob_item[i];
  297. }
  298.  
  299. static object *
  300. list_slice(a, ilow, ihigh)
  301.     listobject *a;
  302.     int ilow, ihigh;
  303. {
  304.     listobject *np;
  305.     int i;
  306.     if (ilow < 0)
  307.         ilow = 0;
  308.     else if (ilow > a->ob_size)
  309.         ilow = a->ob_size;
  310.     if (ihigh < 0)
  311.         ihigh = 0;
  312.     if (ihigh < ilow)
  313.         ihigh = ilow;
  314.     else if (ihigh > a->ob_size)
  315.         ihigh = a->ob_size;
  316.     np = (listobject *) newlistobject(ihigh - ilow);
  317.     if (np == NULL)
  318.         return NULL;
  319.     for (i = ilow; i < ihigh; i++) {
  320.         object *v = a->ob_item[i];
  321.         INCREF(v);
  322.         np->ob_item[i - ilow] = v;
  323.     }
  324.     return (object *)np;
  325. }
  326.  
  327. object *
  328. getlistslice(a, ilow, ihigh)
  329.     object *a;
  330.     int ilow, ihigh;
  331. {
  332.     if (!is_listobject(a)) {
  333.         err_badcall();
  334.         return NULL;
  335.     }
  336.     return list_slice((listobject *)a, ilow, ihigh);
  337. }
  338.  
  339. static object *
  340. list_concat(a, bb)
  341.     listobject *a;
  342.     object *bb;
  343. {
  344.     int size;
  345.     int i;
  346.     listobject *np;
  347.     if (!is_listobject(bb)) {
  348.         err_badarg();
  349.         return NULL;
  350.     }
  351. #define b ((listobject *)bb)
  352.     size = a->ob_size + b->ob_size;
  353.     np = (listobject *) newlistobject(size);
  354.     if (np == NULL) {
  355.         return NULL;
  356.     }
  357.     for (i = 0; i < a->ob_size; i++) {
  358.         object *v = a->ob_item[i];
  359.         INCREF(v);
  360.         np->ob_item[i] = v;
  361.     }
  362.     for (i = 0; i < b->ob_size; i++) {
  363.         object *v = b->ob_item[i];
  364.         INCREF(v);
  365.         np->ob_item[i + a->ob_size] = v;
  366.     }
  367.     return (object *)np;
  368. #undef b
  369. }
  370.  
  371. static object *
  372. list_repeat(a, n)
  373.     listobject *a;
  374.     int n;
  375. {
  376.     int i, j;
  377.     int size;
  378.     listobject *np;
  379.     object **p;
  380.     if (n < 0)
  381.         n = 0;
  382.     size = a->ob_size * n;
  383.     np = (listobject *) newlistobject(size);
  384.     if (np == NULL)
  385.         return NULL;
  386.     p = np->ob_item;
  387.     for (i = 0; i < n; i++) {
  388.         for (j = 0; j < a->ob_size; j++) {
  389.             *p = a->ob_item[j];
  390.             INCREF(*p);
  391.             p++;
  392.         }
  393.     }
  394.     return (object *) np;
  395. }
  396.  
  397. static int
  398. list_ass_slice(a, ilow, ihigh, v)
  399.     listobject *a;
  400.     int ilow, ihigh;
  401.     object *v;
  402. {
  403.     /* Because [X]DECREF can recursively invoke list operations on
  404.        this list, we must postpone all [X]DECREF activity until
  405.        after the list is back in its canonical shape.  Therefore
  406.        we must allocate an additional array, 'recycle', into which
  407.        we temporarily copy the items that are deleted from the
  408.        list. :-( */
  409.     object **recycle, **p;
  410.     object **item;
  411.     int n; /* Size of replacement list */
  412.     int d; /* Change in size */
  413.     int k; /* Loop index */
  414. #define b ((listobject *)v)
  415.     if (v == NULL)
  416.         n = 0;
  417.     else if (is_listobject(v)) {
  418.         n = b->ob_size;
  419.         if (a == b) {
  420.             /* Special case "a[i:j] = a" -- copy b first */
  421.             int ret;
  422.             v = list_slice(b, 0, n);
  423.             ret = list_ass_slice(a, ilow, ihigh, v);
  424.             DECREF(v);
  425.             return ret;
  426.         }
  427.     }
  428.     else {
  429.         err_badarg();
  430.         return -1;
  431.     }
  432.     if (ilow < 0)
  433.         ilow = 0;
  434.     else if (ilow > a->ob_size)
  435.         ilow = a->ob_size;
  436.     if (ihigh < 0)
  437.         ihigh = 0;
  438.     if (ihigh < ilow)
  439.         ihigh = ilow;
  440.     else if (ihigh > a->ob_size)
  441.         ihigh = a->ob_size;
  442.     item = a->ob_item;
  443.     d = n - (ihigh-ilow);
  444.     if (ihigh > ilow)
  445.         p = recycle = NEW(object *, (ihigh-ilow));
  446.     else
  447.         p = recycle = NULL;
  448.     if (d <= 0) { /* Delete -d items; recycle ihigh-ilow items */
  449.         for (k = ilow; k < ihigh; k++)
  450.             *p++ = item[k];
  451.         if (d < 0) {
  452.             for (/*k = ihigh*/; k < a->ob_size; k++)
  453.                 item[k+d] = item[k];
  454.             a->ob_size += d;
  455.             NRESIZE(item, object *, a->ob_size); /* Can't fail */
  456.             a->ob_item = item;
  457.         }
  458.     }
  459.     else { /* Insert d items; recycle ihigh-ilow items */
  460.         NRESIZE(item, object *, a->ob_size + d);
  461.         if (item == NULL) {
  462.             XDEL(recycle);
  463.             err_nomem();
  464.             return -1;
  465.         }
  466.         for (k = a->ob_size; --k >= ihigh; )
  467.             item[k+d] = item[k];
  468.         for (/*k = ihigh-1*/; k >= ilow; --k)
  469.             *p++ = item[k];
  470.         a->ob_item = item;
  471.         a->ob_size += d;
  472.     }
  473.     for (k = 0; k < n; k++, ilow++) {
  474.         object *w = b->ob_item[k];
  475.         XINCREF(w);
  476.         item[ilow] = w;
  477.     }
  478.     if (recycle) {
  479.         while (--p >= recycle)
  480.             XDECREF(*p);
  481.         DEL(recycle);
  482.     }
  483.     return 0;
  484. #undef b
  485. }
  486.  
  487. int
  488. setlistslice(a, ilow, ihigh, v)
  489.     object *a;
  490.     int ilow, ihigh;
  491.     object *v;
  492. {
  493.     if (!is_listobject(a)) {
  494.         err_badcall();
  495.         return -1;
  496.     }
  497.     return list_ass_slice((listobject *)a, ilow, ihigh, v);
  498. }
  499.  
  500. static int
  501. list_ass_item(a, i, v)
  502.     listobject *a;
  503.     int i;
  504.     object *v;
  505. {
  506.     object *old_value;
  507.     if (i < 0 || i >= a->ob_size) {
  508.         err_setstr(IndexError, "list assignment index out of range");
  509.         return -1;
  510.     }
  511.     if (v == NULL)
  512.         return list_ass_slice(a, i, i+1, v);
  513.     INCREF(v);
  514.     old_value = a->ob_item[i];
  515.     a->ob_item[i] = v;
  516.     DECREF(old_value); 
  517.     return 0;
  518. }
  519.  
  520. static object *
  521. ins(self, where, v)
  522.     listobject *self;
  523.     int where;
  524.     object *v;
  525. {
  526.     if (ins1(self, where, v) != 0)
  527.         return NULL;
  528.     INCREF(None);
  529.     return None;
  530. }
  531.  
  532. static object *
  533. listinsert(self, args)
  534.     listobject *self;
  535.     object *args;
  536. {
  537.     int i;
  538.     object *v;
  539.     if (!getargs(args, "(iO)", &i, &v))
  540.         return NULL;
  541.     return ins(self, i, v);
  542. }
  543.  
  544. static object *
  545. listappend(self, args)
  546.     listobject *self;
  547.     object *args;
  548. {
  549.     object *v;
  550.     if (!getargs(args, "O", &v))
  551.         return NULL;
  552.     return ins(self, (int) self->ob_size, v);
  553. }
  554.  
  555. static object *comparefunc;
  556.  
  557. static int
  558. cmp(v, w)
  559.     const ANY *v, *w;
  560. {
  561.     object *t, *res;
  562.     long i;
  563.  
  564.     if (err_occurred())
  565.         return 0;
  566.  
  567.     if (comparefunc == NULL)
  568.         return cmpobject(* (object **) v, * (object **) w);
  569.  
  570.     /* Call the user-supplied comparison function */
  571.     t = mkvalue("(OO)", * (object **) v, * (object **) w);
  572.     if (t == NULL)
  573.         return 0;
  574.     res = call_object(comparefunc, t);
  575.     DECREF(t);
  576.     if (res == NULL)
  577.         return 0;
  578.     if (!is_intobject(res)) {
  579.         err_setstr(TypeError, "comparison function should return int");
  580.         i = 0;
  581.     }
  582.     else {
  583.         i = getintvalue(res);
  584.         if (i < 0)
  585.             i = -1;
  586.         else if (i > 0)
  587.             i = 1;
  588.     }
  589.     DECREF(res);
  590.     return (int) i;
  591. }
  592.  
  593. static object *
  594. listsort(self, args)
  595.     listobject *self;
  596.     object *args;
  597. {
  598.     object *save_comparefunc;
  599.     if (self->ob_size <= 1) {
  600.         INCREF(None);
  601.         return None;
  602.     }
  603.     save_comparefunc = comparefunc;
  604.     comparefunc = args;
  605.     if (comparefunc != NULL) {
  606.         /* Test the comparison function for obvious errors */
  607.         (void) cmp((ANY *)&self->ob_item[0], (ANY *)&self->ob_item[1]);
  608.         if (err_occurred()) {
  609.             comparefunc = save_comparefunc;
  610.             return NULL;
  611.         }
  612.     }
  613.     qsort((char *)self->ob_item,
  614.                 (int) self->ob_size, sizeof(object *), cmp);
  615.     comparefunc = save_comparefunc;
  616.     if (err_occurred())
  617.         return NULL;
  618.     INCREF(None);
  619.     return None;
  620. }
  621.  
  622. static object *
  623. listreverse(self, args)
  624.     listobject *self;
  625.     object *args;
  626. {
  627.     register object **p, **q;
  628.     register object *tmp;
  629.     
  630.     if (args != NULL) {
  631.         err_badarg();
  632.         return NULL;
  633.     }
  634.  
  635.     if (self->ob_size > 1) {
  636.         for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
  637.                         p < q; p++, q--) {
  638.             tmp = *p;
  639.             *p = *q;
  640.             *q = tmp;
  641.         }
  642.     }
  643.     
  644.     INCREF(None);
  645.     return None;
  646. }
  647.  
  648. int
  649. reverselist(v)
  650.     object *v;
  651. {
  652.     if (v == NULL || !is_listobject(v)) {
  653.         err_badcall();
  654.         return -1;
  655.     }
  656.     v = listreverse((listobject *)v, (object *)NULL);
  657.     if (v == NULL)
  658.         return -1;
  659.     DECREF(v);
  660.     return 0;
  661. }
  662.  
  663. int
  664. sortlist(v)
  665.     object *v;
  666. {
  667.     if (v == NULL || !is_listobject(v)) {
  668.         err_badcall();
  669.         return -1;
  670.     }
  671.     v = listsort((listobject *)v, (object *)NULL);
  672.     if (v == NULL)
  673.         return -1;
  674.     DECREF(v);
  675.     return 0;
  676. }
  677.  
  678. object *
  679. listtuple(v)
  680.     object *v;
  681. {
  682.     object *w;
  683.     object **p;
  684.     int n;
  685.     if (v == NULL || !is_listobject(v)) {
  686.         err_badcall();
  687.         return NULL;
  688.     }
  689.     n = ((listobject *)v)->ob_size;
  690.     w = newtupleobject(n);
  691.     if (w == NULL)
  692.         return NULL;
  693.     p = ((tupleobject *)w)->ob_item;
  694.     memcpy((ANY *)p,
  695.            (ANY *)((listobject *)v)->ob_item,
  696.            n*sizeof(object *));
  697.     while (--n >= 0) {
  698.         INCREF(*p);
  699.         p++;
  700.     }
  701.     return w;
  702. }
  703.  
  704. static object *
  705. listindex(self, args)
  706.     listobject *self;
  707.     object *args;
  708. {
  709.     int i;
  710.     
  711.     if (args == NULL) {
  712.         err_badarg();
  713.         return NULL;
  714.     }
  715.     for (i = 0; i < self->ob_size; i++) {
  716.         if (cmpobject(self->ob_item[i], args) == 0)
  717.             return newintobject((long)i);
  718.     }
  719.     err_setstr(ValueError, "list.index(x): x not in list");
  720.     return NULL;
  721. }
  722.  
  723. static object *
  724. listcount(self, args)
  725.     listobject *self;
  726.     object *args;
  727. {
  728.     int count = 0;
  729.     int i;
  730.     
  731.     if (args == NULL) {
  732.         err_badarg();
  733.         return NULL;
  734.     }
  735.     for (i = 0; i < self->ob_size; i++) {
  736.         if (cmpobject(self->ob_item[i], args) == 0)
  737.             count++;
  738.     }
  739.     return newintobject((long)count);
  740. }
  741.  
  742. static object *
  743. listremove(self, args)
  744.     listobject *self;
  745.     object *args;
  746. {
  747.     int i;
  748.     
  749.     if (args == NULL) {
  750.         err_badarg();
  751.         return NULL;
  752.     }
  753.     for (i = 0; i < self->ob_size; i++) {
  754.         if (cmpobject(self->ob_item[i], args) == 0) {
  755.             if (list_ass_slice(self, i, i+1, (object *)NULL) != 0)
  756.                 return NULL;
  757.             INCREF(None);
  758.             return None;
  759.         }
  760.             
  761.     }
  762.     err_setstr(ValueError, "list.remove(x): x not in list");
  763.     return NULL;
  764. }
  765.  
  766. static struct methodlist list_methods[] = {
  767.     {"append",    (method)listappend},
  768.     {"count",    (method)listcount},
  769.     {"index",    (method)listindex},
  770.     {"insert",    (method)listinsert},
  771.     {"sort",    (method)listsort, 0},
  772.     {"remove",    (method)listremove},
  773.     {"reverse",    (method)listreverse},
  774.     {NULL,        NULL}        /* sentinel */
  775. };
  776.  
  777. static object *
  778. list_getattr(f, name)
  779.     listobject *f;
  780.     char *name;
  781. {
  782.     return findmethod(list_methods, (object *)f, name);
  783. }
  784.  
  785. static sequence_methods list_as_sequence = {
  786.     (inquiry)list_length, /*sq_length*/
  787.     (binaryfunc)list_concat, /*sq_concat*/
  788.     (intargfunc)list_repeat, /*sq_repeat*/
  789.     (intargfunc)list_item, /*sq_item*/
  790.     (intintargfunc)list_slice, /*sq_slice*/
  791.     (intobjargproc)list_ass_item, /*sq_ass_item*/
  792.     (intintobjargproc)list_ass_slice, /*sq_ass_slice*/
  793. };
  794.  
  795. typeobject Listtype = {
  796.     OB_HEAD_INIT(&Typetype)
  797.     0,
  798.     "list",
  799.     sizeof(listobject),
  800.     0,
  801.     (destructor)list_dealloc, /*tp_dealloc*/
  802.     (printfunc)list_print, /*tp_print*/
  803.     (getattrfunc)list_getattr, /*tp_getattr*/
  804.     0,        /*tp_setattr*/
  805.     (cmpfunc)list_compare, /*tp_compare*/
  806.     (reprfunc)list_repr, /*tp_repr*/
  807.     0,        /*tp_as_number*/
  808.     &list_as_sequence,    /*tp_as_sequence*/
  809.     0,        /*tp_as_mapping*/
  810. };
  811.